#define  _CRT_SECURE_NO_WARNINGS
#include<deque>

#include<iostream>
using namespace std;

class FrontMiddleBackQueue 
{
public:
    FrontMiddleBackQueue() {}

    void pushFront(int val)
    {
        ans.push_front(val);
    }

    void pushMiddle(int val)
    {
        int sz = ans.size();
        //int insertPos = (sz % 2 == 0) ? (sz / 2) : (sz / 2 + 1);
        int insertPos = sz / 2;
        ans.insert(ans.begin() + insertPos, val);
    }

    void pushBack(int val)
    {
        ans.push_back(val);
    }

    int popFront()
    {
        if (ans.empty()) return -1;
        int ret = ans.front();
        ans.pop_front();
        return ret;
    }

    int popMiddle()
    {
        if (ans.empty()) return -1;
        int sz = ans.size();
        int deletePos = (sz % 2 == 0) ? (sz / 2 - 1) : (sz / 2);
        //int deletePos = sz / 2;
        int ret = ans[deletePos];
        ans.erase(ans.begin() + deletePos);
        return ret;
    }

    int popBack()
    {
        if (ans.empty()) return -1;
        int ret = ans.back();
        ans.pop_back();
        return ret;
    }
private:
    deque<int> ans;
};

int main()
{
    FrontMiddleBackQueue f;
    f.pushFront(1);
    f.pushBack(2);
    f.pushMiddle(3);
    f.pushMiddle(4);
    f.popFront();
    f.popMiddle();
    f.popMiddle();
    f.popBack();
    f.popFront();

	return 0;
}